#include "qintproperty.h"

#include <QSpinBox>

QIntProperty::QIntProperty(SHAREDLIB::QAbstractProperty *parent):
    SHAREDLIB::QAbstractProperty(parent)
{
    connect(this,SIGNAL(showValueChanged()),this,SLOT(value_changed()));
}

void QIntProperty::valueXML(QXmlStreamWriter *w)
{
    w->writeAttribute("value",getValue().toString());
}

QWidget* QIntProperty::getEditor()
{
    if(attribute("editabled").toBool())
    {
        QSpinBox *b=new QSpinBox;
        int min=attribute("min").toInt();
        int max=attribute("max").toInt();
        if(min==max)
        {
            min=-999999999;
            max=999999999;
        }
        b->setRange(min,max);
        connect(b,SIGNAL(valueChanged(int)),this,SLOT(editor(int)));
        m_editor=b;
    }
    return QAbstractProperty::getEditor();
}

void QIntProperty::editor(int value)
{
    int v=getValue().toInt();
    if(v!=value)
    {
        setModified(true);
        setSignalValue(value);
    }
}

void QIntProperty::value_changed()
{
    QSpinBox* b=(QSpinBox*)m_editor;
    if(b!=NULL)
    {
        b->setValue(m_value.toInt());
    }
}
